/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ies.domain.model.util;


import com.ies.domain.model.repository.util.AbstractFacade;
import java.util.LinkedHashMap;

/**
 *
 * @author gustavo
 */
public class JpaPool {

    private static JpaPool instancia;
    protected  LinkedHashMap<Class, AbstractFacade> facades;

    private JpaPool() {
        facades = new LinkedHashMap<Class, AbstractFacade>();
    }

    public static AbstractFacade get(Class classe) {
        return instancia.getFacade(classe);
    }

    public static JpaPool getInstancia() {
        if (instancia == null) {
            instancia = new JpaPool();
        }
        return instancia;
    }

    public static void setInstancia(JpaPool instancia) {
        JpaPool.instancia = instancia;
    }

    public AbstractFacade getFacade(Class classe) {
        if (facades.get(classe) == null) {
            return new AbstractFacade(classe) {
            };
        }
        return facades.get(classe);
    }

    void addFacades(AbstractFacade facade) {
        facades.put(facade.getEntityClass(), facade);
    }
}
